'Zaklada kontakt w ipj.gov.pl
'Obecna skladnia wejscia:
'Imie;Nazwisko;;Dzial (pelna nazwa);Departament (skrocona nazwa dzialu);Pokoj;Telefon;Instytucja (IPJ);;Mail(dla kontaktu);


Option Explicit

Dim oRootDSE
Dim sDomain
Dim oContainer
Dim oContact

Dim sFirstName
Dim sLastName
Dim sUserName
Dim sFullName
Dim sOfficeLocations
Dim sTelephoneNumber
Dim sDescription
Dim sDepartment
Dim sCompany
Dim sDivision
Dim sMail
Dim sTarget

Dim saUserData

Dim sCommandLineArgs
Dim sOneLine

Set sCommandLineArgs = wscript.Arguments

Set oRootDSE = GetObject("LDAP://rootDSE")
sDomain = oRootDSE.Get("defaultNamingContext")
'--->Set oContainer = GetObject("LDAP://cn=Users," & sDomain)
Set oContainer = GetObject("LDAP://ou=CISExchangeDaemon,ou=Instytut," & sDomain)



WScript.StdOut.Write("Wczytywanie danych wejsciowych")
WScript.StdOut.WriteBlankLines(1)

sOneLine = sCommandLineArgs(0)
saUserData = Split(sOneLine, ";", -1, 1)

sFirstName       = saUserData(0) '"Jan"
sLastName        = saUserData(1) '"Abacki"
sFullName        = sLastName & " " & sFirstName
sUserName        = saUserData(1) & left(sFirstName, 1)
sDivision        = saUserData(3) '"Dzial Ekonomiczno-Handlowy"
sDepartment	 = saUserData(4) '"DEH"
sOfficeLocations = saUserData(5) '"bud.7, pok.21"
sTelephoneNumber = saUserData(6) '"718 05 35"
sDescription     = sLastName & " " & sFirstName & ", " & sDivision & ", " & sOfficeLocations
sCompany	 = saUserData(7) '"IPJ"
sTarget		 = "SMTP:" & saUserData(9) '"J.Abacki@gmail.com"


WScript.StdOut.Write("Poprawnie wczytano dane wejsciowe")
WScript.StdOut.WriteBlankLines(1)

WScript.StdOut.Write("Tworzenie kontaktu w AD")
WScript.StdOut.WriteBlankLines(1)

Set oContact = oContainer.Create("contact", "cn=" & sFullName)

Dim strMailbox
strMailbox = "/o=First Organization/ou=First Administrative Group/cn=Recipients/cn=" & sUserName

oContact.Put "givenName", sFirstName
oContact.Put "sn", sLastName
oContact.Put "displayName", sFullName

oContact.Put "description", sDescription
oContact.Put "physicalDeliveryOfficeName", sOfficeLocations
oContact.Put "telephoneNumber", sTelephoneNumber
oContact.Put "department", sDepartment
oContact.Put "division", sDivision
oContact.Put "company", sCompany

oContact.Put "targetAddress", sTarget
oContact.Put "legacyExchangeDN", strMailbox
oContact.Put "mailNickname", sUserName
oContact.SetInfo

WScript.StdOut.Write("Poprawnie wpisano do AD")
WScript.StdOut.WriteBlankLines(1)

